Add optional Claude Code hook for blocking malicious packages#172
Open
David Larsen (dc-larsen) wants to merge 2 commits intomainfrom
Open
Add optional Claude Code hook for blocking malicious packages#172David Larsen (dc-larsen) wants to merge 2 commits intomainfrom
David Larsen (dc-larsen) wants to merge 2 commits intomainfrom
Conversation
Adds a PreToolUse hook (hooks/socket-gate.ts) that intercepts package install commands across npm, PyPI, Cargo, RubyGems, Go, and NuGet, and queries the public Socket MCP server at https://mcp.socket.dev/ to block packages with a supply chain score below 20 (known malware, typosquats, high-risk supply chain signals). - No API key, CLI, or registration required - Fails open on network, parse, and timeout errors - 23 tests (8 unit + 15 integration), all passing Inspired by https://blog.jimmyvo.com/posts/claudes-dependency-hook/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
PreToolUsehook (hooks/socket-gate.ts) for Claude Code that intercepts package install commands and queries the public Socket MCP server before allowing installation.20(known malware, typosquats, high-risk signals)https://mcp.socket.dev/directly--experimental-strip-types— no build step, no extra depsReplaces #168 (which used the Socket CLI + API key). Design simplified after review feedback.
Files
hooks/socket-gate.tshooks/socket-gate.test.tsREADME.mdSupported commands
npm install,npm i,npm add,yarn add,pnpm add,bun addpip install,pip3 install,uv add,uv pip install,poetry add,pipenv installcargo add,cargo installgem install,bundle addgo get,go installdotnet add package,nuget installHow it works
PreToolUseJSON payload on stdin for everyBashcallinitializethen atools/callfor thedepscoretool againsthttps://mcp.socket.dev/supplyChain < 20, it returnsdenywith a reason that includes the score and asocket.devreview linkallowTest results
Inspired by Jimmy Vo's dependency hook.